package com.example.task01_servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SessionServlet3", value = "/session3")
public class SessionServlet3 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取Session对象
        HttpSession session = request.getSession();
        //2.获取对象的默认失效时间并打印
        int maxInactiveInterval = session.getMaxInactiveInterval();
        System.out.println("获取到的失效时间为:"+maxInactiveInterval);
        //3.修改失效时间后重新获取并打印
        session.setMaxInactiveInterval(1200);
        maxInactiveInterval = session.getMaxInactiveInterval();
        System.out.println("获取到的失效时间为:"+maxInactiveInterval);

    }
}
